package com.jingdianjichi.project.domain.handler.subject;

import com.jingdianjichi.project.common.enums.IsDeletedFlagEnum;
import com.jingdianjichi.project.common.enums.SubjectInfoTypeEnum;
import com.jingdianjichi.project.domain.bo.SubjectAnswerBo;
import com.jingdianjichi.project.domain.bo.SubjectInfoBo;
import com.jingdianjichi.project.domain.bo.SubjectOptionBo;
import com.jingdianjichi.project.domain.convert.JudgeSubjectConverter;
import com.jingdianjichi.project.infra.basic.entity.SubjectJudge;
import com.jingdianjichi.project.infra.basic.service.SubjectJudgeService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * ClassName:RadioTypeHandler
 * Package:com.jingdianjichi.subject.domain.handler.subject
 * Description:
 *
 * @Author fst
 * @Create 2024/9/29 13:29
 * @Version 1.0
 */


/**
 * 判断题目
 */
@Component
public class JudgeTypeHandler implements SubjectTypeHandler
{

    @Resource
    private SubjectJudgeService subjectJudgeService;

    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.JUDGE;
    }

    @Override
    public void add(SubjectInfoBo subjectInfoBo)
    {
        //判断题目的插入
        SubjectJudge subjectJudge = new SubjectJudge();
        SubjectAnswerBo subjectAnswerBO = subjectInfoBo.getOptionList().get(0);
        subjectJudge.setSubjectId(subjectInfoBo.getId());
        subjectJudge.setIsCorrect(subjectAnswerBO.getIsCorrect());
        subjectJudge.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
        subjectJudgeService.insert(subjectJudge);
    }

    @Override
    public SubjectOptionBo query(int subjectId) {
        SubjectJudge subjectJudge = new SubjectJudge();
        subjectJudge.setSubjectId(Long.valueOf(subjectId));
        List<SubjectJudge> result = subjectJudgeService.queryByCondition(subjectJudge);
        List<SubjectAnswerBo> subjectAnswerBOList = JudgeSubjectConverter.INSTANCE.convertEntityToBoList(result);
        SubjectOptionBo subjectOptionBO = new SubjectOptionBo();
        subjectOptionBO.setOptionList(subjectAnswerBOList);
        return subjectOptionBO;

    }
}
